<template>
  <a-form v-if="search.length > 0" layout="inline" :model="form">
    <a-form-item v-for="(v, k) in search" :key="k">
      <a-input v-if="v.type == 'input'" v-model:value="form[v.key]" :placeholder="v.text">
      </a-input>

      <a-radio-group v-if="v.type == 'radio'" v-model:value="form[v.key]" :options="v.options" />
    </a-form-item>
    <a-form-item>
      <a-button :loading="loading" type="primary" @click="searchAction"> 搜索</a-button>
    </a-form-item>
  </a-form>

  {{ form }}
</template>

<script setup>
import { onMounted, ref } from 'vue'

const emits = defineEmits(['search'])

const props = defineProps({
  search: {
    type: Array,
    default: []
  },
  loading: {
    type: Boolean,
    default: false
  }
})

const form = ref({})

const a = ref('')

const searchAction = () => {
  console.log(111)
  emits('search', form.value)
}

onMounted(() => {
  if (props.search) {
    for (let i = 0; i < props.search.length; i++) {
      form.value[props.search[i].key] = ''
    }
  }
})
</script>

<style scoped></style>
